package com.r2coding.system.controller;

import com.r2coding.common.enums.Module;
import com.r2coding.common.enums.OperationType;
import com.r2coding.system.annotation.SysLog;
import com.r2coding.system.vo.req.QueryOpinionReqVo;
import com.r2coding.system.vo.resp.OpinionResponseVo;
import org.springframework.beans.factory.annotation.Autowired;

import com.r2coding.system.entity.OpinionEntity;
import com.r2coding.system.service.OpinionService;
import com.r2coding.common.util.Result;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 用户意见
 *
 * @author 98k灬
 * @email hk666zx@163.com
 * @date 2022-08-12 13:00:08
 */
@RestController
@RequestMapping("/opinion")
public class OpinionController {
    @Autowired
    private OpinionService opinionService;

    /**
     * 列表
     */
    @PostMapping("/list")
    public Result list(@RequestBody QueryOpinionReqVo req) {
        OpinionResponseVo info = opinionService.listOpinion(req);
        return Result.ok(info);
    }

    /**
     * 修改
     */
    @SysLog(module = Module.OPINION, operationType = OperationType.UPDATE, description = "更新用户反馈")
    @PreAuthorize("hasAuthority('opinion:edit')")
    @PostMapping("/update")
    public Result update(@RequestBody OpinionEntity opinion){
        opinionService.updateOpinion(opinion);
        return Result.ok();
    }

    /**
     * 删除
     */
    @SysLog(module = Module.OPINION, operationType = OperationType.DELETE, description = "删除用户反馈")
    @PreAuthorize("hasAuthority('opinion:delete')")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Integer id){
		opinionService.removeById(id);
        return Result.ok();
    }
}
